package me.zhengjie.modules.web.rest.poster;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.config.entity.ResponseBaseEntity;
import me.zhengjie.config.enums.AtmrErrorEnum;
import me.zhengjie.config.exception.WeChatException;
import me.zhengjie.modules.web.domain.poster.PosterRequest;
import me.zhengjie.modules.web.domain.poster.PosterResponse;
import me.zhengjie.modules.web.service.poster.ISharePosterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("web/poster")
@Api(tags = "前端接口-海报")
public class SharePosterController {

    @Autowired
    private ISharePosterService sharePosterService;

    @PostMapping("list")
    @ApiOperation(value = "WEB-海报列表")
    public ResponseBaseEntity list(@RequestBody PosterRequest requestEntity) {
        ResponseBaseEntity response = new ResponseBaseEntity();
        try {
            if (Objects.isNull(requestEntity.getType())) {
                throw new WeChatException("缺少参数");
            }
            List<PosterResponse> result = sharePosterService.posterList(requestEntity.getType());
            response.setBody(result);
        } catch (WeChatException e) {
            response.getHeader().setErrCode("-1");
            response.getHeader().setErrMsg(e.getMsg());
        } catch (Exception e) {
            response.getHeader().setErrCode(AtmrErrorEnum.EC_ALL_99999.getErrorCode());
            response.getHeader().setErrMsg(AtmrErrorEnum.EC_ALL_99999.getErrorMessage());
        }
        return response;
    }
}
